package leetcode.二叉树;

import java.util.*;
import java.util.stream.Collectors;

public class 二叉树中第二小的节点671 {
    private List<Integer> list = new ArrayList<>();
    public int findSecondMinimumValue(TreeNode root) {
        list.clear();
        process(root);
        list.sort(Integer::compareTo);
        int min = list.get(0);
        for (Integer integer : list) {
            if(integer > min)
                return integer;
        }
        return -1;
    }

    private void process(TreeNode root) {
        if(root == null)
            return;
        list.add(root.val);
        process(root.left);
        process(root.right);
    }
}
